package com.qingcheng.config;

import org.apache.http.client.config.RequestConfig;
import org.elasticsearch.client.RestClientBuilder;
import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientBuilderCustomizer;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName ESConfig
 * @Description 默认响应时间只有30秒，查询大量的数据时30秒的时间一般都不够用。更改客户端的超时限制
 * @Author Simon
 * @Date 2020/8/28 15:28
 * @Version 1.0
 **/
@Configuration
public class ESConfig  implements RestClientBuilderCustomizer {
    @Override
    public void customize(RestClientBuilder builder) {
        builder.setMaxRetryTimeoutMillis(300 * 1000).setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback(){

            @Override
            public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
                return requestConfigBuilder.setConnectTimeout(30000)
                        .setSocketTimeout(20601000);//更改客户端的超时限制默认30秒现在改为20分钟
            }
        });
    }
}
